package DBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ResourceBundle;

/**
 * @program: gusys
 * @description: 数据库连接工具类
 * @author: 王代涛
 **/
@SuppressWarnings("JavaDoc")
public class DatabaseConnection {
    private static final String DBDRIVER = ResourceBundle.getBundle("jdbc").getString("driver");
    private static final String DBURL = ResourceBundle.getBundle("jdbc").getString("url");
    private static final String DBUSER = ResourceBundle.getBundle("jdbc").getString("user");
    private static final String DBPASSWORD = ResourceBundle.getBundle("jdbc").getString("password");
    private Connection conn;

    /**
     * 加载驱动信息
     */
    public DatabaseConnection() {
        try {
            Class.forName(DBDRIVER);
            this.conn = DriverManager.getConnection(DBURL, DBUSER, DBPASSWORD);
        }catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 判断数据连接是否操作
     */
    public void close() {
        if(this.conn != null) {
            try {
                this.conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public Connection getConn() {
        return this.conn;
    }

}

